package com.hq.myvideo;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;

import java.util.ArrayList;
import java.util.List;

/**
 * 滑动视频适配器
 */
public class FullPlayerAdapter extends RecyclerView.Adapter<FullPlayerAdapter.Holder>{
    private List<String> date =null;
   FullPlayerAdapter(){
       this.date = new ArrayList<>();
       String uir = "https://m3u8.49cdn.com/newhd/202205/6285df56a4abea1e9312f982/hls/index.m3u8";
       for (int i=0;i<20;i++){
           this.date.add(uir);
       }

   }
    @NonNull
    @Override
    public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        // 加载布局页面
        LayoutInflater from = LayoutInflater.from(parent.getContext());
        // from
        View view = from.inflate(R.layout.full_player_item, parent, false);

        return new Holder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull Holder holder, int position) {
        holder.upimage(this.date.get(position));
    }

    @Override
    public int getItemCount() {
        return this.date.size();
    }

    /**
     * 滑动视频适配器 数据填充
     */
    public class Holder extends RecyclerView.ViewHolder{
        private StandardGSYVideoPlayer player = null;

        public Holder(@NonNull View itemView) {
            super(itemView);


          this.player =  (StandardGSYVideoPlayer)itemView.findViewById(R.id.vp);


        }
        public void upimage(String path){

            String source1 = "https://m3u8.49cdn.com/newhd/202205/6285df56a4abea1e9312f982/hls/index.m3u8";
            this.player.setUp(path, true, "测试视频");
            //增加title
            this.player.getTitleTextView().setVisibility(View.VISIBLE);
            this.player.startPlayLogic();
        }
    }
}
